package com.windowes.weichang.subscribe;

import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.JedisPubSub;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/7/14 下午6:28
 * @description:
 *
 **/
@Slf4j
public class RedisSubscribe extends JedisPubSub {


    TaskHandleService taskHandleService;

    public RedisSubscribe(TaskHandleService taskHandleService) {
        this.taskHandleService = taskHandleService;
    }

    // 取得订阅的消息后的处理
    @Override

    public void onMessage(String channel, String message) {
        log.info("onMessage: channel[" + channel + "], message[" + message + "]");
        taskHandleService.handle(message);
    }

    // 取得按表达式的方式订阅的消息后的处理
    @Override
    public void onPMessage(String pattern, String channel, String message) {
        log.info("onPMessage: pattern[" + pattern + "],channel[" + channel + "], message[" + message + "]");
    }

    // 初始化按表达式的方式订阅时候的处理
    @Override
    public void onPSubscribe(String channel, int subscribedChannels) {
        log.info("onSubscribe: channel[" + channel + "]," + "subscribedChannels[" + subscribedChannels + "]");
    }

    // 取消按表达式的方式订阅时候的处理
    @Override
    public void onPUnsubscribe(String channel, int subscribedChannels) {
        log.info("onUnsubscribe: channel[" + channel + "], " + "subscribedChannels[" + subscribedChannels + "]");
    }

    // 初始化订阅时候的处理
    @Override
    public void onSubscribe(String pattern, int subscribedChannels) {
        log.info(
                "onPUnsubscribe: pattern[" + pattern + "]," + "subscribedChannels[" + subscribedChannels + "]");
    }

    // 取消订阅时候的处理
    @Override
    public void onUnsubscribe(String pattern, int subscribedChannels) {
        log.info("onPSubscribe: pattern[" + pattern + "], " + "subscribedChannels[" + subscribedChannels + "]");
    }

}
